#include "ScopeManager.h"
#include "neiderra/utils/Logger.h"
#include <iostream>
#include <stack>

using namespace std;
using namespace neiderra::utils::script;

ScopeManager::ScopeManager(Core* core): Base(core)
{
	scope.push_back("$");
	size=0;
	i=j=0;
}

ScopeManager::~ScopeManager(){}

void ScopeManager::openScope(string s)
{
	string x = getScope()+s+"$";
	scope.push_back(x);
	size++;
	
	core->getLogger()->log(string("scope -> ") + x);
	//j++;
	//cout <<"enter:"<<x<<" "<< i << j << size << endl;
}

void ScopeManager::closeScope()
{
	scope.pop_back();
	size--;
	//cout << "backto: "<<scope[size]<<endl;
	
	core->getLogger()->log("scope <-");
}

void ScopeManager::closeScope(int times)
{

}

string ScopeManager::getScope(void)
{
	//cout << scope[size] <<endl;
	return scope[size];
}

string ScopeManager::prev_current(void)
{
	//cout << "prevcurrent: "<< GetScope() << endl;
	return scope[size-j];
}

string ScopeManager::prev(void)
{
	j++;
	if(scope.empty()) throw top();
	if(j>size) throw top();
	else {	
		return scope[size-j];
	}
}

void ScopeManager::reset(void){ j=0; }

